package com.chenxiao.Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: CX
 * @Date: Created in  2024/04/07 15:29
 * @version: v1.0
 * @Description: TODO
 **/
public class Subject implements Observable{
    // 观察者列表(订阅用户)
    private List<Observer> list = new ArrayList<>();
    @Override
    public void add(Observer observer) {
        list.add(observer);
    }

    @Override
    public void del(Observer observer) {
        list.remove(observer);
    }

    @Override
    public void notify(String message) {
        list.forEach(observer -> observer.update(message));
    }
}
